package com.android.dopewars;

import java.util.Vector;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;


public class Mugged extends Activity {
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.mugged);
        LinearLayout message_container = (LinearLayout)findViewById(R.id.mugged_messages);
        
        Vector<Integer> color_toggle = new Vector<Integer>();
        color_toggle.add(Color.rgb(64,64,64));
        color_toggle.add(Color.rgb(84,84,84));
        int next_color = 0;
        
        double money_lost_choice = Global.rand_gen_.nextDouble();
        TextView money_lost = new TextView(this);
        money_lost.setLayoutParams(new LinearLayout.LayoutParams(
        		LinearLayout.LayoutParams.FILL_PARENT,
        		LinearLayout.LayoutParams.WRAP_CONTENT));
        money_lost.setTextSize((float)20.0);
        money_lost.setBackgroundColor(next_color);
        money_lost.setTextColor(Color.WHITE);
        next_color = (next_color + 1) % 2;
        
        if (money_lost_choice < 0.05) {
			Global.dealer_.setCash((int)(0.1 * Global.dealer_.cash()));
			int message_choice = Global.rand_gen_.nextInt(3);
			switch (message_choice) {
			case 0:
				money_lost.setText("They came at you out of nowhere, like spider monkeys! They took almost every cookie!");
				break;
			case 1:
				money_lost.setText("One of 'em looked just like Cookie Monster. Needless to say you gave them almost everything you had.");
				break;
			case 2:
				money_lost.setText("You started to say \"That's not a knife...\" when you realized it was in fact a gun. They left you with cab fare.");
				break;
			}
		} else if (money_lost_choice < 0.25) {
			Global.dealer_.setCash(Global.dealer_.cash() / 2);
			int message_choice = Global.rand_gen_.nextInt(3);
			switch (message_choice) {
			case 0:
				money_lost.setText("They took about half of your money. Just like taxes, right? At least this way someone will get something useful from the money.");
				break;
			case 1:
				money_lost.setText("You offered them everything for your life. They said they would feel bad taking more than $" + Integer.toString(Global.dealer_.cash()));
				break;
			case 2:
				money_lost.setText("You kicked their butts! At least that's what you'll tell everyone. Really they took half of your money.");
				break;
			}
		} else {
			int money_lost_amount = (int)((0.1 + 0.1 * Global.rand_gen_.nextDouble()) *
					Global.dealer_.cash());
			Global.dealer_.setCash(Global.dealer_.cash() - money_lost_amount);
			int message_choice = Global.rand_gen_.nextInt(20);
			switch (message_choice) {
			case 0:
				money_lost.setText("Baker Smith strikes again! Your pockets are $" + Integer.toString(money_lost_amount) + " lighter.");
				break;
			case 1:
				money_lost.setText("Baker Smith got the drop on you. He let you live for $" + Integer.toString(money_lost_amount));
				break;
			case 2:
				money_lost.setText("You got taken for $" + Integer.toString(money_lost_amount) + " so fast you barely saw it happen. They say that cat Baker Smith is a bad mother...");
				break;
			case 3:
				money_lost.setText("A mugger wearing a Baker Smith mask demanded $" + Integer.toString(money_lost_amount) + ". He's just crazy enough to wear a mask of himself. Best not to risk it, you paid up.");
				break;
			case 4:
				money_lost.setText("You stopped to enjoy the fall breeze, and in seconds Baker Smith was halfway down the street with $" + Integer.toString(money_lost_amount) + " of your money!");
				break;
			case 5:
			case 6:
			case 7:
			case 8:
			case 9:
				money_lost.setText("Common everyday muggers held you up for $" + Integer.toString(money_lost_amount));
				break;
			case 10:
			case 11:
				money_lost.setText("Your assistant put a gun to your head for $" + Integer.toString(money_lost_amount));
				break;
			case 12:
			case 13:
			case 14:
			case 15:
				money_lost.setText("A major magazine editor wants to do a story on you, but you need to greese the wheels first: $" + Integer.toString(money_lost_amount));
				break;
			case 16:
			case 17:
			case 18:
				money_lost.setText("Your truck was not in that loading zone more than 5 minutes! Impound Charge: $" + Integer.toString(money_lost_amount));
				break;
			case 19:
				money_lost.setText("Bakery Oven on the fritz again. Get it fixed: $" + Integer.toString(money_lost_amount));
				break;
			}
		}
        message_container.addView(money_lost);
        
        for (int i = Global.dealer_.numGuns() - 1; i >= 0; --i) {
			if (Global.rand_gen_.nextDouble() < 0.2) {
				TextView gun_lost = new TextView(this);
				gun_lost.setLayoutParams(new LinearLayout.LayoutParams(
		        		LinearLayout.LayoutParams.FILL_PARENT,
		        		LinearLayout.LayoutParams.WRAP_CONTENT));
				gun_lost.setTextSize((float)20.0);
				gun_lost.setBackgroundColor(next_color);
				gun_lost.setTextColor(Color.WHITE);
		        next_color = (next_color + 1) % 2;
		        
		        message_container.addView(gun_lost);
		        
		        int message_choice = Global.rand_gen_.nextInt(3);
				switch (message_choice) {
				case 0:
					gun_lost.setText("You dropped your " + Global.dealer_.gun(i).name() + " in the gutter trying to defend yourself!");
					break;
				case 1:
					gun_lost.setText("Bye bye " + Global.dealer_.gun(i).name());
					break;
				case 2:
					gun_lost.setText("You got taken for your " + Global.dealer_.gun(i).name() + ". Not that big of a deal, it didn't stop you from getting mugged anyway, did it?");
					break;
				}
		        
				Global.dealer_.removeGun(i);
			}
		}
        
        ((Button)findViewById(R.id.mugged_okay)).setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		Intent i = new Intent();
        		setResult(RESULT_OK, i);
        		finish();
        	}
        });
        
        WindowManager.LayoutParams dialog_params = getWindow().getAttributes();
    	dialog_params.width = WindowManager.LayoutParams.FILL_PARENT;
    	getWindow().setAttributes(dialog_params);
    }
}
